package cn.edu.scnu.service;

import cn.edu.scnu.entity.Comment;
import cn.edu.scnu.mapper.CommentMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentService extends ServiceImpl<CommentMapper, Comment> {
    @Autowired
    private CommentMapper commentMapper;

    // 根据电影id查询评论
    public List<Comment> findCommentByMovieId(Integer movieId) {
        QueryWrapper<Comment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("movie_id", movieId);
        List<Comment> commentList = commentMapper.selectList(queryWrapper);
        return commentList;
    }

    // 添加评论
    public void addComment(String commentContent, String phone, Integer movieId) {
        Comment comment = new Comment();
        comment.setCommentContent(commentContent);
        comment.setPhone(phone);
        comment.setMovieId(movieId);
        commentMapper.insert(comment);
    }
}
